//
//  LoginController.m
//  ProjectForCustomer
//
//  Created by 钟游 on 2019/8/25.
//  Copyright © 2019年 钟游. All rights reserved.
//

#import "LoginController.h"
#import "LoginMainView.h"
#import "LoginViewModel.h"
#import "ThirdLoginController.h"
#import "DelegateController.h"
#import "AddInfoController.h"

@interface LoginController ()
@property(nonatomic,strong)LoginMainView * mainView;
@property(nonatomic,strong)LoginViewModel * viewModel;
@end

@implementation LoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}
-(void)zy_getNewData{
  //  [self.viewModel.weiSubject sendNext:nil];
}
-(void)zy_addSubviews{
    self.mainView.frame = self.view.bounds;
    [self.view addSubview:self.mainView];
}
-(void)zy_bindViewModel{
    
    [[self.viewModel.loginSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id  _Nullable x) {
        if ([x isKindOfClass:[NSDictionary class]]) {
            [StorageManager setProperty:x forKey:@"userInfo"];
        }
    }];
    [[self.viewModel.thirdLoginSubject takeUntil:self.rac_willDeallocSignal]subscribeNext:^(id  _Nullable x) {
        if ([x isKindOfClass:[NSDictionary class]]) {
            NSDictionary * info = x;
            [StorageManager setProperty:x forKey:@"userInfo"];
            if ([info[@"needPhone"]integerValue]==0) {
                
                ThirdLoginController * third = [[ThirdLoginController alloc]init];
                third.infoDict = info;
                [self.navigationController pushViewController:third animated:YES];
            }else{
                AddInfoController * add =[[AddInfoController alloc]init];
                add.fromSource = @"1";
                [self.navigationController pushViewController:add animated:YES];
            }
        }
    }];
    [[self.viewModel.wbSubject takeUntil:self.rac_willDeallocSignal]subscribeNext:^(id  _Nullable x) {
        DelegateController * delegate =[[DelegateController alloc]init];
        delegate.urlPath = @"license";
        [self.navigationController pushViewController:delegate animated:YES];
    }];
    [[self.viewModel.qqSubject takeUntil:self.rac_willDeallocSignal]subscribeNext:^(id  _Nullable x) {
        DelegateController * delegate =[[DelegateController alloc]init];
        delegate.urlPath = @"policy";
        [self.navigationController pushViewController:delegate animated:YES];
    }];
}
#pragma mark --lazy
-(LoginMainView *)mainView{
    if (!_mainView) {
        _mainView=[[LoginMainView alloc]initWithViewModel:self.viewModel];
    }
    return _mainView;
}
-(LoginViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel=[[LoginViewModel alloc]init];
    }
    return _viewModel;
}
@end
